package autopeople.controller;

import javax.inject.Inject;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.Source;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import autopeople.tools.ResourceTool;
import autopeople.tools.TransformerTool;

@Controller
public class PeopleController extends AbstractController {

	@Inject
	private ResourceTool resourceTool;

	@Inject
	private TransformerTool transformerTool;

	@RequestMapping(value = "/people")
	public String readPeople(HttpServletRequest req, HttpServletResponse res)
			throws Exception {

		// Get files from file-path
		final Source xsltSource = resourceTool.getSourceFile("/people.xsl");
		final Source xmlSource = resourceTool.getSourceFile("/people.xml");

		// Transform to html and create view people.jsp in WEB-INF/jsp
		transformerTool.transformXMLandXSLTIntoJspFileToBeUsedAsView(
				xsltSource, xmlSource);

		// return view
		return "people";
	}

	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		// TODO Auto-generated method stub
		return null;
	}
}
